<template>
    <div class="cont mb-4">
        <CustomQuery @submit="changeQuery" :form-columns="queryList"></CustomQuery>
    </div>
    <div class="cont">
        <CustomTable selection :columns="columns" :data-source="data">
            <template #column-head="{ record }">
                <img class="w-18 h-18 rounded-full" :src="record.head" alt="用户头像">
            </template>
            <template #column-state="{ column }">
                <a-tag color="green">活跃</a-tag>
            </template>
            <template #column-action="{ column }">
                <a-button type="primary" :icon="h(EditOutlined)">编辑</a-button>
            </template>
        </CustomTable>
    </div>
</template>

<script setup lang="ts">
import { PlusOutlined, EditOutlined } from '@ant-design/icons-vue';
import { h } from 'vue'

import CustomTable from '@/components/customTable/CustomTable.vue';
import CustomQuery from '@/components/customQuery/CustomQuery.vue';
import { CustomQueryColumns, CustomQueryValue } from '@/components/customQuery/types';
import { CustomTableColumns, CUstomTableData } from '@/components/customTable/types';

const queryList = reactive<CustomQueryColumns[]>([
    { label: '用户编号', key: 'code', type: 'input' },
    { label: '订单编号', key: 'orderCode', type: 'input' },
    { label: '骑手编号', key: 'riderId', type: 'input' },
    { label: '用户手机号', key: 'userPhone', type: 'input' },
    {
        label: '状态', key: 'state', type: 'select', options: [
            { label: '状态: 全部', value: '1' },
            { label: '状态: 启用', value: '2' },
            { label: '状态: 禁用', value: '3' },
        ],value:'1'
    },
])

const changeQuery = (queryState: CustomQueryValue) => {
    alert('查询结果为' + JSON.stringify(queryState))
}

const data = ref<CUstomTableData[]>([])
const columns = reactive<CustomTableColumns[]>([
    {
        title: "编号",
        dataIndex: "code",
        key: "code",
    },
    {
        title: "下单用户",
        dataIndex: "user",
        key: "user",
    },
    {
        title: "下单金额",
        dataIndex: "money",
        key: "money",
    },
    {
        title: "下单信息",
        dataIndex: "info",
        key: "info",
    },
    {
        title: "状态",
        dataIndex: "state",
        key: "state",
        bodyCell: 'state'
    },
    {
        title: "售后",
        dataIndex: "afterSales",
        key: "afterSales",
    },
    {
        title: "时间",
        dataIndex: "time",
        key: "time",
    },
    {
        flag: 'ACTION'
    },
]);


onMounted(() => {
    for (let i = 0; i < 100; i++) {
        data.value.push(
            { code: '01', user: '已经很棒了',money: '19.9',info: '下单信息', userPhone: '13236774266', afterSales: '已完成', state: '1', time: '2024-08-16' },
        )
    }
})
</script>

<style scoped></style>